/**
 * @file     firstUniqChar.js
 * @brief    [387. 字符串中的第一个唯一字符](https://leetcode.cn/problems/first-unique-character-in-a-string/description/)
 * @author   Zhu
 * @date     2023-02-12 17:53
 */

/**
 * @param {string} s
 * @return {number}
 */
var firstUniqChar = function (s) {
    const map = {};
    for (let i = 0; i < s.length; i++) {
        const count = map[s[i]] ?? 0;
        map[s[i]] = count + 1;
    }
    for (let i = 0; i < s.length; i++) {
        if (map[s[i]] === 1) {
            return i;
        }
    }

    return -1;
};
